package com.lovo.roomProject.updatePwd.dao.impl;

import com.lovo.roomProject.dao.BaseDAO;
import com.lovo.roomProject.pojo.SystemDO;
import com.lovo.roomProject.system.service.SystemService;
import com.lovo.roomProject.system.service.impl.SystemServiceImpl;
import com.lovo.roomProject.updatePwd.dao.UpdatePwdDAO;

public class UpdatePwdDAOImpl extends BaseDAO implements UpdatePwdDAO {
    private SystemService systemService = new SystemServiceImpl();
    @Override
    public void changePwd(SystemDO loginUser, String iptOldPwd, String iptNewPwd, String iptConfirmPwd) throws Exception {
        String loginOldPwd = loginUser.getPassword();//原有的密码
        boolean bl = iptNewPwd.matches("^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$");
        if (loginOldPwd.equals(iptOldPwd)) {
            if (!bl) {
                throw new Exception("密码格式错误,请重新输入");
            } else if (iptOldPwd.equals(iptNewPwd)) {
                throw new Exception("新密码不能和旧密码相同,请重新输入");
            } else if (!iptNewPwd.equals(iptConfirmPwd)) {
                throw new Exception("新密码和确认密码不一致,请重新输入");
            } else {
                loginUser.setPassword(iptConfirmPwd);
                systemService.updateSystem(loginUser);
            }
        } else {
            throw new Exception("旧密码不匹配,请重新输入");
        }
    }
}
